# The planner's problem with infinite horizon
# constrained solution

###############   Declaration of Parameters   #############################
#-- Households' parameters
param BETA;
param SIGMA;
param CHI;      # entrepreneur share
param NU;


#-- Firms' parameters
param A;        # aggregate productivity
param ALPHA;    # capital share


#-- Financial market parameters
param eta_0;    # does not matter in unconstrained steady state
param eta_1;    # does not matter in unconstrained steady state
   
#-- Calibration target
param G_Y;
param I_Y;
param L_target;

###############   Declaration of Variables ################################
var C >= 0;
var L >= 0;
var K >= 0;
var B >= 0;
var phi >=0, <=1;
var lambda >=0;
var gamma  >=0;
var Psi >=0;


var q_w >= 1;
var q   >= 1;
var eta >= 0;
var rho >= 0;

var MU_L;
var u_p_C;
var u_pp_C;
var eta_p;



#------ Declaration of prices to be solved in the .run file-----------------
var tau_k;
var tau_l;
var R;

#------ to be calibrated
var G >=0;
var MU >=0;
var DELTA >=0;


#################### The Planner's Constraints#############################

subject to soc:
C + G + (1 + phi * eta) * K = A * K^ALPHA * L^(1 - ALPHA) + (1 + (1 - CHI) * phi * eta) * (1 - DELTA) * K;

subject to fin_constr:
CHI * B / BETA  + (1 + CHI * rho) * ((1 - (1 - CHI) * phi * q) * (1 - DELTA) - (1 - phi * q)) * K = 0;

subject to implementability:
u_p_C * (C + B + q_w * K) = MU_L * L + u_p_C * (B + q_w * K) / BETA;

subject to foc_consumption:
(1 + Psi) * u_p_C + Psi * u_pp_C * (C + B + (1 + phi * eta) * K)
+ gamma * u_pp_C * ((1 - (1 - CHI) * phi * q) * (1 - DELTA) * K - (1 - phi * q) * K)
- lambda
= - gamma * u_pp_C * CHI * B / (1 + CHI * rho) + Psi * u_pp_C * (q_w * K + B);

subject to foc_labor:
MU * L^NU * (1 + Psi) + Psi * MU * NU * L^NU = lambda * A * (1 - ALPHA) * K^ALPHA * L^(-ALPHA);

subject to foc_capital:
BETA * (A * ALPHA * K^(ALPHA - 1) * L^(1 - ALPHA) + 1 - DELTA) = 1;

subject to foc_bond:
gamma = 0;

subject to foc_asset_liquidity:
phi = 0;

#----------------------- definitions
subject to def_u_p_C:
u_p_C = C^(-SIGMA);

subject to def_u_pp_C:
u_pp_C = (-SIGMA) * C^(-SIGMA - 1);

subject to def_v_p_L:
MU_L = MU * L^NU;

subject to def_eta:
eta = eta_0 * phi^eta_1;

subject to def_eta_p:
eta_p = eta_0 * eta_1 * phi^(eta_1 - 1);

subject to def_q:
q_w = 1 + eta + (1 - phi) * phi * eta_p;

subject to def_q_w:
q = q_w - eta;

subject to def_rho:
rho * (1 - phi^2 * eta_p) = eta + phi * eta_p;


#################### Declaration of Policy Implementation #########################

# back out taxes and interest rates
subject to capital_tax:
q_w = BETA * ((1 - tau_k) * A * ALPHA * K^(ALPHA - 1) * L^(1 - ALPHA) + (1 - DELTA) * q_w + CHI * (1 - DELTA) * phi * (q * (1 + rho) - q_w));

subject to labor_tax:
(1 - tau_l) * A * (1 - ALPHA) * K^ALPHA * L^(-ALPHA) * u_p_C = MU_L;

subject to interest_rate:
1 = BETA  * (1 + CHI * rho) * R;

################## Targets if under calibration
subject to I_Y_target:
DELTA * K = A * K^ALPHA * L^(1 - ALPHA) * I_Y;

subject to G_Y_target:
G = A * K^ALPHA * L^(1 - ALPHA) * G_Y;

subject to labor_supply_target:
L = L_target;

